//
//  KDMessageController.m
//  WangJingApp
//
//  Created by 魏强 on 16/12/30.
//  Copyright © 2016年 KDTech. All rights reserved.
//

#import "KDMessageController.h"
#import "WQSearchController.h"
#import "KDNavigationController.h"
@interface KDMessageController ()<UITableViewDelegate, UITableViewDataSource,WQSearchControllerDelegate, UISearchBarDelegate>
/**  <#Description#> */
@property (nonatomic, weak) UITableView *tableView;
/**  <#Description#> */
@property (nonatomic, weak) UIView *headerView;
@property (nonatomic, strong) KDNavigationController *searchController;
/**  <#Description#> */
@property (nonatomic, strong) NSArray *infoArr;

@end

@implementation KDMessageController
#pragma mark - 懒加载区
- (NSArray *)infoArr
{
    if (!_infoArr) {
        _infoArr = @[@[@"手机通讯录"],@[@"辽宁省厅",@"黑龙江省厅"]] ;
    }
    return _infoArr;
}
#pragma mark - 生命周期区
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"联系人";
    
    [self setupNav];
    [self setupTableView];
    
}

#pragma mark - 板块布置区
- (void)setupNav{
    
}

- (void)setupTableView{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0  , 0, screenW, screenH - 44) style:UITableViewStyleGrouped];
    self.tableView = tableView;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.editing = YES;
    tableView.tag = 1000;
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenW, 100)];
    UISearchBar *searchbar = [[UISearchBar alloc]initWithFrame:CGRectMake(10, 10, screenW - 20, 30)];
    searchbar.placeholder = @"搜索";
    searchbar.delegate = self;
    [headerView addSubview:searchbar];
    
    tableView.tableHeaderView = headerView;
    
    tableView.tableFooterView = [UIView new];
    tableView.separatorColor = BackGroundColor;
    tableView.backgroundColor = BackGroundColor;
    [self.view addSubview:tableView];
}
#pragma mark - 事件点击区
- (void)searchBarClick{
    WQSearchController *ctr = [[WQSearchController alloc]initWithNibName:@"WQSearchController" bundle:nil];
    ctr.delegate = self;
    self.searchController = [[KDNavigationController alloc]initWithRootViewController:ctr];
    
    [ctr showInViewController:self];
}
#pragma mark - 网络请求区

#pragma mark - 通知接收区

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.infoArr.count;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *arr = self.infoArr[section];
        return  arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId =@"messageCell";
    NSArray *arr = self.infoArr[indexPath.section];
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        cell.textLabel.text = arr[indexPath.row];
        //cell.imageView.image =
    }
    return cell;

}
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

#pragma mark - UISearchBarDelegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
    [self searchBarClick];
    return YES;
}

- (void)questionSearchCancelButtonClicked:(WQSearchController *)controller{
    [controller hide:^{
        KDLog(@"questionSearchCancelButtonClicked");
    }];
}
@end
